'use strict';

angular.module('myApp.classes_add', ['tm.pagination'])
.controller('classes_addCtrl',function($scope,$http,$location){
	$('#teacher').height(75);
	$scope.selectGrades=[
		{id : 1,name : '一年级'},
		{id : 2,name : '二年级'},
		{id : 3,name : '三年级'},
		{id : 4,name : '四年级'},
		{id : 5,name : '五年级'},
		{id : 6,name : '六年级'}
	];
	$scope.selectGrade = $scope.selectGrades[0].id;

	// 班主任：所有的老师
	$http.get('v1/teacher').success(function(data){
		$scope.selectTeacheres = [];
		var data = data.result.data;
		for (var i = 0; i < data.length; i++) {
			$scope.selectTeacheres.push({'id':data[i].id,'name':data[i].name});
		};
		$scope.selectTeacher = $scope.selectTeacheres[0].id;
	})
	//任课老师
	$http({
		    url: 'v1/teacher', 
		    method: "GET",
		    params: {column: 'subject_id',content:'1'}
		 }).success(function(data){
			$scope.selectTeacheres = [];
			var data = data.result.data;
			for (var i = 0; i < data.length; i++) {
				$scope.selectTeacheres.push({'id':data[i].id,'name':data[i].name});
			};
			$scope.selectTeacher = $scope.selectTeacheres[0].id;
	})


	//所有的课程
	$http.get('v1/subject').success(function(data){
		$scope.selectSubjects = [];
		var data = data.result;
		for (var i = 0; i < data.length; i++) {
			$scope.selectSubjects.push({'id':data[i].id,'name':data[i].name});
		};
		$scope.subjects = [];
		$scope.subjects.push({'name':$scope.selectSubjects[0].id});

		$scope.add = function(){
			var height = $('#teacher').height();
			height+=75;
			$('#teacher').height(height);
			var length = $scope.subjects.length;
			$scope.subjects.push({'name':$scope.selectSubjects[length].id});

			var subjects_length = $scope.subjects.length-1;
			var subject_id = $scope.subjects[subjects_length].name;

			var teachers_arr = [];

			$http({
				    url: 'v1/teacher', 
				    method: "GET",
				    params: {column: 'subject_id',content:subject_id}
				 }).success(function(data){

					var data = data.result.data;
					for (var i = 0; i < data.length; i++) {
						teachers_arr.push({'id':data[i].id,'name':data[i].name});
					};
					$scope.selectTeacheres.push(teachers_arr);
					var teachers_length = $scope.teachers.length;
					$scope.teachers.push({'name':$scope.selectTeacheres[teachers_length][0].id});
					console.log($scope.teachers);
			})
		}
	})

});